<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<!DOCTYPE html>
<html>
<head>
    <title>课程信息显示</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入bootstrap -->
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.min.css">
    <!-- 引入JQuery  bootstrap.js-->
    <script src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap-paginator.js"></script>
    <script src="${pageContext.request.contextPath}/layer/layer.js"></script>

    <script>
        $(function () {
            //分页
            $('#pagination').bootstrapPaginator({
                bootstrapMajorVersion: 3,
                currentPage:${pageInfo.pageNum},
                totalPages:${pageInfo.pages},
                onPageClicked:function (event, originalEvent, type, page) {
                    $('#pageNum').val(page);
                    $('#form1').submit();
                },
                itemTexts:function (type,page,current) {
                    switch (type) {
                        case "first":
                            return "首页";
                        case "prev":
                            return "上一页";
                        case "next":
                            return "下一页";
                        case "last":
                            return "末页";
                        case "page":
                            return page;
                    }
                }
            });
        });
        //显示删除的模态框
        function showDeleteModal(id) {
            $('#deleteCourseId').val(id);

            $('#deleteProductModal').modal('show');
        }
        //删除该课程
        function deleteCourse() {
            alert("hello");
            $.get(
                '${pageContext.request.contextPath}/admin/deleteCourse',
                {'courseID':$('#deleteCourseId')},
                function (result) {
                    alert("world");
                    if(result.status == 1) {
                        lay.msg('删除成功',{
                            time:1500,
                            skin:'successMsg'
                        },function () {
                            location.href='${pageContext.request.contextPath}/admin/findAll?pageNum='+'${pageInfo.pageNum}';
                        });
                    }
                }
            );
        }
    </script>
</head>
<body>
<jsp:include page="top.jsp"/>
<!-- 中间主体 -->
<div class="container" id="content">
    <div class="row">
        <div class="col-md-2">
            <jsp:include page="menu.jsp"/>
        </div>
        <div class="col-md-10">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="row">
                        <h1 class="col-md-5">课程名单管理</h1>
                        <form class="bs-example bs-example-form col-md-5" role="form" style="margin: 20px 0 10px 0;"
                              action="${pageContext.request.contextPath}/admin/searchCourse" id="form1" method="post">
                            <div class="input-group">
                                <input type="hidden" name="pageNum" value="${pageInfo.pageNum}" id="pageNum">
                                <input type="text" class="form-control" placeholder="请输入姓名" name="findByName" value="${conditionName}">
                                <span class="input-group-addon btn" onclick="document.getElementById('form1').submit"
                                      id="sub">搜索</span>
                            </div>
                        </form>
                        <button class="btn btn-default col-md-2" style="margin-top: 20px" onClick="location.href='${pageContext.request.contextPath}/admin/addCoursePage'">
                            添加课程信息
                            <sapn class="glyphicon glyphicon-plus"/>
                        </button>
                    </div>
                </div>
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>课程号</th>
                        <th>课程名称</th>
                        <th>授课老师编号</th>
                        <th>上课时间</th>
                        <th>上课地点</th>
                        <th>周数</th>
                        <th>课程类型</th>
                        <th>学分</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${pageInfo.list}" var="course">
                        <tr>
                            <td>${course.courseID}</td>
                            <td>${course.courseName}</td>
                            <td>${course.teacherID}</td>
                            <td>${course.courseTime}</td>
                            <td>${course.classRoom}</td>
                            <td>${course.courseWeek}</td>
                            <td>${course.courseType}</td>
                            <td>${course.score}</td>
                            <td>
                                <button class="btn btn-default btn-xs btn-info"
                                        onClick="location.href='${pageContext.request.contextPath}/admin/editCoursePage?id=${course.courseID}'">
                                    修改
                                </button>
                                <button class="btn btn-default btn-xs btn-danger btn-primary"
                                        onclick="location.href='${pageContext.request.contextPath}/admin/deleteCourse?courseID=${course.courseID}'">
                                    删除
                                </button>
                                <%--<input type="button" class="btn btn-warning btn-sm doProDelete" value="删除" onclick="showDeleteModal(${course.courseID});">--%>
                                <!--弹出框-->
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <div class="panel-footer text-center">
                    <%--使用bootstrap-pagination实现分页插件--%>
                    <ul id="pagination"></ul>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="container" id="footer">
    <div class="row">
        <div class="col-md-12"></div>
    </div>
</div>
<!-- 确认删除 start -->
<div class="modal fade" tabindex="-1" id="deleteProductModal">
    <!-- 窗口声明 -->
    <div class="modal-dialog">
        <!-- 内容声明 -->
        <form action="" method="post" class="form-horizontal">
            <div class="modal-content">
                <!-- 头部、主体、脚注 -->
                <div class="modal-header">
                    <button class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">提示消息</h4>
                </div>
                <div class="modal-body text-center row text-center">
                    <h4>确认要删除该课程吗？</h4>
                </div>
                <div class="modal-footer">
                    <input type="hidden" id="deleteCourseId">
                    <button class="btn btn-primary updatePro" type="submit" data-dimiss="modal" onclick="deleteCourse();">确认</button>
                    <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                </div>
            </div>
        </form>
    </div>
</div>
<!-- 确认删除 end -->
</body>
<script type="text/javascript">
    // <%--设置菜单中--%>
    $("#nav li:nth-child(1)").addClass("active")
    <c:if test="${pagingVO != null}">
    if (${pagingVO.curentPageNo} == ${pagingVO.totalCount}) {
        $(".pagination li:last-child").addClass("disabled")
    }
    ;

    if (${pagingVO.curentPageNo} == ${1}) {
        $(".pagination li:nth-child(1)").addClass("disabled")
    }
    ;
    </c:if>

    function confirmd() {
        var msg = "您真的确定要删除吗？！";
        if (confirm(msg) == true) {
            return true;
        } else {
            return false;
        }
    }

    $("#sub").click(function () {
        $("#form1").submit();
    });
</script>
</html>
